package com.qianchen.chatbot.api.dto;

import java.util.ArrayList;
import java.util.HashMap;

public class ResponseResult {
    private int code;
    private String message;
    private long timestamp;
    private Object data;

    private ResponseResult(int code, String message) {
        this.setTimestamp(System.currentTimeMillis());
        this.code = code;
        this.message = message;
    }

    public static ResponseResult successInstance() {
        return new ResponseResult(0, StatusCodeConfig.getValue(String.valueOf(0)));
    }

    public static ResponseResult failInstance() {
        return new ResponseResult(-1, StatusCodeConfig.getValue(String.valueOf(-1)));
    }

    public static ResponseResult failInstance(String message) {
        return new ResponseResult(-1, message);
    }

    public static ResponseResult instance(int code) {
        return instance(code, "");
    }

    public static ResponseResult instance(int code, String altMessage) {
        String errorMsg = StatusCodeConfig.getValue(String.valueOf(code));
        return new ResponseResult(code, "".equals(errorMsg) ? altMessage : errorMsg);
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public Object getData() {
        return this.data;
    }

    public ResponseResult setData(Object data) {
        this.data = data;
        return this;
    }

    public ResponseResult createEmptyData() {
        return this.setData(new HashMap());
    }

    public ResponseResult createEmptyList() {
        return this.setData(new ArrayList());
    }
}
